define([ "app", "jquery", "md5", "ecb","artDialog","iframeTools",  "services/UserService","services/TipsService",
		"directives/AudioPlayer",
		"resources/company/CompanyResource", 
		"resources/UserResource", "resources/ShareResource" ],
		function(app) {
			var deps = [ "$scope", "$state","$sce", "$timeout", "$window","$modalInstance", "$location", "$stateParams","TipsService", "UserService", "UserResource", "ShareResource","CompanyResource" ];

			function controller($scope, $state,$sce,$timeout, $window,$modalInstance, $location, $stateParams,TipsService, UserService, UserResource, ShareResource,CompanyResource) {
				
				/**
				 * 获取验证码
				 * 手机号
				 * 短信类型 1：小程序 2：企业端 3:重新认证
				 */
				$scope.sendSms =function(type){
					if($scope.companyVo ==null){
						art.dialog.alert("请输入手机号！",null)
		        		return;
					}
					if($scope.companyVo.mobile == null){
						art.dialog.alert("请输入手机号！",null);
		        		return;
		        	}
					CompanyResource.sendSms($scope.companyVo.mobile,type).success(function(data){
		        		// 返回成功
						art.dialog.alert("发送成功！",null);
		            });
				};
				/**
				 * 取消
				 */
				$scope.cancel =function(type){
					$modalInstance.close();
				};
				
				/**
				 * 第一次认证
				 */
				$scope.check =function(){
					if($scope.companyVo ==null){
						art.dialog.alert("请输入手机号！",null)
		        		return;
					}
					if($scope.companyVo.mobile == null){
						art.dialog.alert("请输入手机号！",null);
		        		return;
		        	}
					
					CompanyResource.check($scope.companyVo.mobile,$scope.companyVo.checkCode,3).success(function(data){
		        		// 验证成功
						if(data.resCode=="0000"){
							$("#showfirst").hide();
							$("#showtow").show();
						}else{
							art.dialog.alert("重新绑定失败！",null);
						}
		            });
				};
				
				$scope.check1 =function(){
					if($scope.companyVo ==null){
						art.dialog.alert("请输入手机号！",null)
		        		return;
					}
					if($scope.companyVo.mobile == null){
						art.dialog.alert("请输入手机号！",null);
		        		return;
		        	}
					
					CompanyResource.bind($scope.companyVo.mobile,$scope.companyVo.checkCode,4).success(function(data){
		        		// 验证成功
						if(data.resCode=="0000"){
							$modalInstance.close();
							// 跳转到登陆页面
							CompanyResource.logout().success(function(data){
								$scope.user = UserService.getCurrentUser();
								UserService.removeCurrentUser();
								$location.path("/findPassword");
				            });
							
						}else{
							art.dialog.alert("重新绑定失败！",null);
						}
		            });
				};
				
				
				
				art.alert = function (content, callback) {
				    return _proxyDialog({
				        id: 'Alert',
				        zIndex:"99999999",
				        icon: 'warning',
				        fixed: true,
				        lock: true,
				        content: content,
				        ok: true,
				        close: callback
				    });
				};
			}
			controller.$inject = deps;
			return app.lazy.controller("ReAuthController", controller);
		});
